<template>
  <div>
    <h2>房号添加</h2>
   <hr>
   <table>
    <tr>
      <td>房号:</td>
      <td>
        <input type="text" v-model="state.fh">
      </td>
    </tr>
    <tr>
      <td>房号状态:</td>
      <td>
        <input type="radio" v-model="state.fhzt" :value="true" checked>启用
        <input type="radio" v-model="state.fhzt" :value="false">停用

      </td>
    </tr>
    <tr>
      <td>
        <input type="button" value="房号添加" @click="FangHaoAdd">
      </td>
      <td>
          <input type="button" value="房型列表" @click="FangXingShow" />
        </td>
    </tr>
   </table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs,onMounted } from 'vue';
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';

const router=useRouter();
const route=useRoute();

let data:any=reactive({
  state:{
    fh:'',
    fhzt:true
  }
  
})

let {state}=toRefs(data);

function FangHaoAdd(){
  let obj={
    fh:state.value.fh,
    fhzt:state.value.fhzt
  }
  if(obj.fh=="")
  {
    alert('房号不能为空')
    return
  }
  axios({
    url:'https://localhost:7071/api/FangHao/FangHaoAdd',
    method:'post',
    data:obj
  })
  .then(res=>{
    if(res.data.data==-1)
  {
    alert('房号名称不能重复')
    return
  }
  if(res.data.data>0)
  {
    alert('添加成功')
    
  }
  else{
    alert('添加失败')
    return
  }
  })
}

function FangXingShow(){
  router.push('/FangXingShow')
}


</script>

<style scoped>

</style>